class_name SoundManager
extends Node


enum Sound {
	CLICK,
	EAT_FOOD,
	GO,
	GRUNT,
	GUNSHOT,
	HIT1,
	HIT2,
	KNIFE_HIT,
	SWOOSH
}

@onready var sounds: Array[AudioStreamPlayer] = [
	$SFX_Click,
	$SFX_EatFood,
	$SFX_Go,
	$SFX_Grunt,
	$SFX_Gunshot,
	$SFX_Hit1,
	$SFX_Hit2,
	$SFX_KnifeHit,
	$SFX_Swoosh
]


func _play_sfx(sfx: Sound, pitch_scale: float, volumne: float = 0.0):
	var player := sounds[sfx]
	player.pitch_scale = pitch_scale
	player.volume_db = volumne
	player.play()


func play(sfx: Sound, tweak_pitch: bool = false):
	var pitch_scale: float = 1.0
	if tweak_pitch:
		pitch_scale = randf_range(0.8, 1.2)
	_play_sfx(sfx, pitch_scale)


func play_death():
	var pitch_scale := randf_range(0.8, 1.2)
	_play_sfx(Sound.GRUNT, pitch_scale, -0.8)
